<template>
	<view class="saleAppoint">
		<uni-nav-bar color="#ffffff" background-color="#00aded" :statusBar="true" title="发货通知单" fixed="true" left-icon="left" left-text="返回" @clickLeft="back" />
		<view class="saleAppoint_top">
			<!-- 搜索 -->
			<!-- 搜索 -->
			<dil-search :columnData="options.columnDataList" @onSearch="onSearch" v-if="options.columnDataList.length > 0"></dil-search>
		</view>
		<view class="saleAppoint_main">
			<dil-card class="dilCard" @emitEvent="emitEvent" v-bind.sync="options"></dil-card>
		</view>
		<view class="saleAppoint_floot"></view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex';
export default {
	data() {
		return {
			options: {
				requestUrl: '/api/v1/ams/selectDlivDirNo?apiId=633',
				requestQuery: {},
				cardSlotList: [
					{
						label: '删除',
						icon: 'trash',
						emitEvent: 'deleteRequirement',
						showCondition: "['未允许发货'].includes(item.dlivProgCd)"
					},
					{
						label: '允许发货',
						icon: 'wlIcon-shenhe',
						emitEvent: 'updaeAppointStatus',
						arguments: {
							dlivProgCd: 0,
							updaeAppointStatusTips: '允许发货'
						},
						showCondition: "['未允许发货'].includes(item.dlivProgCd)"
					},
					{
						label: '弃审',
						icon: 'wlIcon-qishen',
						emitEvent: 'updaeAppointStatus',
						arguments: {
							dlivProgCd: 1,
							updaeAppointStatusTips: '弃审'
						},
						showCondition: "['允许发货'].includes(item.dlivProgCd)"
					},
					{
						label: '运输详情',
						icon: 'bars',
						emitEvent: 'transOrderBrowse',
						showCondition: "['正在执行'].includes(item.dlivProgCd)"
					},
					{
						label: '授权承运商',
						icon: 'wlIcon-xinzeng',
						emitEvent: 'salePlanAdd',
						showCondition: "['允许发货','正在执行'].includes(item.dlivProgCd)"
					}
				],
				columnDataList: [],
				totalNum: 0
			}
		};
	},
	onShow() {
		uni.$emit('onShow', 1);
	},
	mounted() {},
	methods: {
		async getOrderSection(data = {}) {
			this.options.requestQuery = { ...this.options.requestQuery };
		},
		onSearch(item) {
			this.options.requestQuery = JSON.parse(JSON.stringify(item));
		},
		back() {
			uni.switchTab({
				url: '/pages/index/index'
			});
		},
		emitEvent(eventName, cardItem) {
			this[eventName](cardItem);
		},
		transOrderBrowse(item) {
			uni.navigateTo({
				url:
					'/pages/transOrder/saleTransOrder?params=' +
					JSON.stringify({
						requirementId: item.transRequirementId
					})
			});
		},
		updaeAppointStatus(item) {
			let content = `是否${item.updaeAppointStatusTips}该发货通知单`;
			uni.showModal({
				cancelText: '取消',
				confirmText: '确定',
				title: '提示',
				content: content,
				success: (res) => {
					if (res.confirm) {
						this.updaeAppointStatusItem(item);
					} else {
						uni.showToast({
							title: '用户取消操作',
							type: 'info',
							duration: 2000
						});
					}
				}
			});
		},
		async updaeAppointStatusItem(item) {
			let map = {
				mapList: [item]
			};
			const res = await this.$myRequest({
				url: '/api/v1/ams/updateOrder',
				data: map
			}).catch((err) => {
				uni.showToast({
					duration: 2000,
					title: err,
					icon: 'error'
				});
			});
			if (res.data.status == 'succeed') {
				uni.showToast({
					title: res.data.message,
					icon: 'success',
					duration: 2000
				});
				setTimeout(() => {
					this.getOrderSection();
				}, 2200);
			} else {
				uni.showToast({
					title: res.data.message,
					icon: 'error',
					duration: 2000
				});
			}
		},
		deleteRequirement(item) {
			uni.showModal({
				cancelText: '取消',
				confirmText: '确定',
				title: '提示',
				content: '确认删除该发货通知单?',
				success: (res) => {
					if (res.confirm) {
						this.deleteRequirementItem(item);
					} else {
						uni.showToast({
							title: '用户取消操作',
							type: 'info',
							duration: 2000
						});
					}
				}
			});
		},
		async deleteRequirementItem(item) {
			const res = await this.$myRequest({
				url: '/api/v1/ams/deleteDlivDirno',
				data: item
			}).catch((err) => {
				uni.showToast({
					duration: 2000,
					title: err,
					icon: 'error'
				});
			});
			if (res.data.status == 'succeed') {
				uni.showToast({
					title: res.data.message,
					icon: 'success',
					duration: 2000
				});
				setTimeout(() => {
					this.getOrderSection();
				}, 2200);
			} else {
				uni.showToast({
					title: res.data.message,
					icon: 'error',
					duration: 2000
				});
			}
		},
		async salePlanAdd(cardItem) {
			cardItem.planNumber = cardItem.numberRequire;
			this.updateSaleAppointItem({ ...cardItem });
			uni.navigateTo({
				url: '/pages/transPlan/salePlanAdd'
			});
		},
		//vuex
		...mapMutations('sale', ['updateSaleAppointItem']),
		//以下是vuex;
		...mapMutations('sale', ['updateSaleAppointItem'])
	}
};
</script>

<style lang="scss" scoped>
.saleAppoint {
	width: 100vw;
	height: 100%;
	background-color: #f5f5f5;
	&_top {
		background-color: #fff;
	}
	&_main {
	}
	&_floot {
	}
}
</style>
